package evi.com.evi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import evi.com.evi.R;
import evi.com.evi.activity.GoodsManagerActivity;
import evi.com.evi.bean.ClassifyBean;
import evi.com.evi.utils.ToastUtils;

public class ListSortAdapter extends BaseAdapter {

	public List<ClassifyBean> list;
	private Context context;
	public int dataIndex = 0;

	public ListSortAdapter(Context context, List<ClassifyBean> list) {
		this.context = context;
		this.list = list;
		if(null == this.list){
			this.list = new ArrayList<>();
		}
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		PopViewHolder popHolder = null;
		if (convertView != null) {
			popHolder = (PopViewHolder) convertView.getTag();
		} else {
			convertView = LayoutInflater.from(context).inflate(R.layout.item_lv_goods_sort, null);
			popHolder = new PopViewHolder();
			popHolder.rl_layout_item = (RelativeLayout) convertView.findViewById(R.id.rl_layout_item);
			popHolder.tv_info = (TextView) convertView.findViewById(R.id.tv_popu_text);
			convertView.setTag(popHolder);
		}

		if (dataIndex == position) {
			popHolder.rl_layout_item.setBackgroundResource(R.color.pub_textcolor_yellow);
			popHolder.tv_info.setTextColor(0xffffffff);
		} else {
			popHolder.rl_layout_item.setBackgroundResource(R.color.pub_color_white);
			popHolder.tv_info.setTextColor(0xffaaaaaa);
		}

		popHolder.tv_info.setText(list.get(position).getName());

		return convertView;
	}

	class PopViewHolder {
		RelativeLayout rl_layout_item;
		TextView tv_info;
	}
}
